class TapCounter {
  int _tapCount = 0;
  DateTime? _lastTapTime;

  TapCounter();

  int onTap() {
    final now = DateTime.now();
    var lastTappedAt = _lastTapTime;

    if (lastTappedAt == null) {
      _tapCount = 0;
      lastTappedAt = now;
    }

    if ((now.difference(lastTappedAt)) < Duration(milliseconds: 1500)) {
      _tapCount++;
    } else {
      _tapCount = 1;
    }

    _lastTapTime = now;
    return _tapCount;
  }
}
